home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / relnotes / selections / inst-get < prev    next >
Text File  |  2002-10-07  |  3KB  |  119 lines

  1. #!/usr/bin/perl
  2. #
  3. # inst-get -- inspired by all the requests for Debian "apt-get" functionality
  4. #             in IRIX's inst. This is a crude implementation, as it is
  5. #             just a wrapper around "wget" and "inst". Since inst has
  6. #             slow startup and shutdown, this script can be very slow,
  7. #             in addition to how slow downloading the packages is over
  8. #             your internet connection. 
  9. #
  10. # Usage:
  11. #    inst-get [-v] [-d <dir>] package [package ...]
  12. #        "-v" sets wget to be verbose.
  13. #        "-d <dir>" uses a non-default directory
  14. #        "package" is a (usually) unique name part to get
  15. #
  16. # Author:
  17. #    Scott Henry <scotth@sgi.com>, 2001-05-08
  18. #
  19. # License:    What the heck:
  20. #    (C) Copyright 2001-2002 Scott Henry and Silicon Graphics, Inc
  21. #    This program is distributed under the GNU Public License,
  22. #    version 2. There is no warranty on this software, use at
  23. #    your own risk.
  24. #
  25. # History:
  26. #    0.1    (2001-05-08) first version, does downloads only.
  27. #               It doesn't know about "or" dependencies, and
  28. #        downloads all of them...
  29.  
  30. use Getopt::Std;
  31. #
  32. # Some sites (like here) may need to use SOCKS to get out to the Internet
  33. # Uncomment and modify as needed
  34. #
  35. # $ENV{"SOCKS_SERVER"} = "";
  36. # $ENV{"SOCKS_NS"} = "";
  37. $SOCKS = "";            # pmsocks or whatever
  38.  
  39. getopts("vd:") or die "Usage: $0 [-v] [-d dir] package [package ...]\n";
  40.  
  41. $FW_URL = "http://freeware.sgi.com/Dist";
  42. $WGET = "/usr/freeware/bin/wget";
  43. $WG_OPTS = "-q";
  44. if ($opt_v) {
  45.     $WG_OPTS = "";
  46. }
  47. $DIST_DIR = $opt_d ? $opt_d : "/var/tmp/inst-get";
  48. -d $DIST_DIR or mkdir $DIST_DIR,0775 or die "Can't mkdir $DIST_DIR? $?\n";
  49.  
  50. chdir $DIST_DIR or die "Can't cd to $DIST_DIR? $?\n";
  51.  
  52. @pkgs = @ARGV;        # initial packages to download
  53. unless (@pkgs) {
  54.     die "Nothing to fetch? no packages on command line\n";
  55. }
  56.  
  57. # grab the directory listing of the freeware site.
  58. # also makes sure that we can access it.
  59. if ($SOCKS) {
  60.        system($SOCKS, $WGET, $WG_OPTS, $FW_URL."/.");
  61. } else {
  62.        system($WGET, $WG_OPTS, $FW_URL."/.");
  63. }
  64.  
  65. # parse the package tardist names from the downloaded index file.
  66. @packages = ();
  67. open(R, "<index.html") or die "Failed to download index.html from $FW_URL?\n";
  68. while(<R>) {
  69.     next unless /HREF=\"([^\/\"]+)\"/;
  70.     push @packages, $1;
  71. }
  72. close(R);
  73.  
  74. # setup the inst stuff
  75. $CMDFILE = "cmd.file";
  76. open(C, ">$CMDFILE") or die "Can't create inst command file? $?\n";
  77. print C "install prereqs\nconflicts\nkeep *\nquit\n";
  78. close(C);
  79. $INSTCMD = "/usr/sbin/inst -E -M -f . -c $CMDFILE -I default";
  80.  
  81. $downloaded = 0;
  82. # now loop while we have packages to fetch.
  83. while ($#pkgs >= 0) {
  84.     @fetch = ();        # clear it out
  85.     # convert package name to tardist file
  86.     foreach $p (@pkgs) {
  87.         push(@fetch, grep(/$p/, @packages));
  88.     }
  89.     if ($#fetch < 0) {
  90.         die "no packages found to download\nMisspelled package names or broken dependencies?\n";
  91.     }
  92.     # download each tardist file in turn
  93.     foreach $p (@fetch) {
  94.         if (-f $p) {
  95.             print "$p already downloaded\n";
  96.         } else {
  97.             print "downloading $p ...";
  98.             system($SOCKS, $WGET, $WG_OPTS, $FW_URL."/".$p);
  99.             system("/usr/bin/tar", "-xf", $p);
  100.             $downloaded++;
  101.             print "\n";
  102.         }
  103.     }
  104.     # now run inst on the files
  105.     @pkgs = ();
  106.     open(I, "$INSTCMD |");
  107.     while(<I>) {
  108.         last if /^No conflicts/;
  109.         next unless /Also install\s+([-_\w]+)\.[-_\w]+\.[-_\w]+\s/;
  110.         push @pkgs, $1;
  111.         while(<I>) {
  112.             last unless /\s([-_\w]+)\.[-_\w]+\.[-_\w]+\s/;
  113.             push @pkgs, $1;
  114.         }
  115.     }
  116.     close(I);
  117. }
  118. print "$downloaded packages fetched\n";
  119.